package com.duobaoyu.dby.supply.admin.controller.config;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.duobaoyu.dby.channel.adapter.enums.OperationTypeEnum;
import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.supply.admin.annotation.SupplySysLog;
import com.duobaoyu.dby.supply.biz.client.resource.ResourceBusinessConfigAdminClient;
import com.duobaoyu.dby.supply.biz.client.resource.bean.dto.BusinessConfigDTO;
import com.duobaoyu.dby.supply.biz.client.resource.bean.dto.BusinessConfigQueryDTO;
import com.duobaoyu.dby.supply.biz.client.resource.bean.vo.BusinessConfigInfoVO;
import com.duobaoyu.dby.supply.biz.client.resource.bean.vo.BusinessConfigVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 业务管理
 * @author liyang
 * @version 1.0.0
 * @ClassName BusinessConfigController
 * @Description 业务配置Controller
 * @createTime 10:13:00 2023/10/16
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/biz/config")
@Api(value = "biz-config", tags = "业务配置表")
public class BusinessConfigController {

    private final ResourceBusinessConfigAdminClient resourceBusinessConfigAdminClient;

    /**
     * 查询业务配置分页列表
     * @param bizConfigQuery
     * @return
     */
    @GetMapping("/query/page")
    @ApiOperation(value = "查询业务配置", notes = "查询业务配置")
    @SupplySysLog(value = "查询业务配置",operationType = OperationTypeEnum.SELECT)
    public R<Page<BusinessConfigInfoVO>> queryPage(BusinessConfigQueryDTO bizConfigQuery) {

        return R.ok(resourceBusinessConfigAdminClient.queryPage(bizConfigQuery));
    }

    /**
     * 查询业务配置明细
     * @param id
     * @return
     */
    @GetMapping("/query/details/{id}")
    @ApiOperation(value = "查询业务配置", notes = "查询业务配置")
    @SupplySysLog(value = "查询业务配置详情",operationType = OperationTypeEnum.SELECT)
    public R<BusinessConfigInfoVO> details(@NotNull(message = "参数不能为空") @PathVariable("id") Long id) {

        return R.ok(resourceBusinessConfigAdminClient.details(id));
    }

    /**
     * 保存业务配置
     * @param businessConfig
     * @return
     */
    @PostMapping("/save")
    @ApiOperation(value = "保存业务配置", notes = "保存业务配置")
    @SupplySysLog(value = "保存业务配置",operationType = OperationTypeEnum.INTERT)
    public R<Boolean> save(@RequestBody BusinessConfigDTO businessConfig) {

        return R.ok(resourceBusinessConfigAdminClient.saveBusinessConfig(businessConfig));
    }

    /**
     * 删除业务配置
     * @param configIds
     * @return
     */
    @PostMapping("/remove")
    @ApiOperation(value = "删除业务配置", notes = "删除业务配置")
    @SupplySysLog(value = "删除业务配置",operationType = OperationTypeEnum.DELETE)
    public R<Boolean> remove(@RequestBody @Validated List<Long> configIds) {

        return R.ok(resourceBusinessConfigAdminClient.removeConfigIds(configIds));
    }

    /**
     * 删除业务配置缓存
     * @return
     */
    @PostMapping("/delete/cache")
    @ApiOperation(value = "删除业务配置缓存", notes = "删除业务配置缓存")
    @SupplySysLog(value = "删除业务配置缓存",operationType = OperationTypeEnum.DELETE)
    public R<Boolean> deleteCache() {

        return R.ok(resourceBusinessConfigAdminClient.deleteCache());
    }

    /**
     * 获取商品映射业务配置
     * @return
     */
    @PostMapping("/get/product-mapping-biz-config")
    @ApiOperation(value = "获取商品映射业务配置", notes = "获取商品映射业务配置")
    @SupplySysLog(value = "获取商品映射业务配置",operationType = OperationTypeEnum.SELECT)
    public R<List<BusinessConfigVO>> getProductMappingBizConfig() {

        return R.ok(resourceBusinessConfigAdminClient.getProductMappingBizConfig());
    }

    /**
     * 获取业务配置
     * @return
     */
    @GetMapping("/get/biz-config")
    @ApiOperation(value = "获取业务配置", notes = "获取业务配置")
    @SupplySysLog(value = "获取业务配置",operationType = OperationTypeEnum.SELECT)
    public R<List<BusinessConfigVO>> getBizConfig() {

        return R.ok(resourceBusinessConfigAdminClient.getBizConfig());
    }
}
